const CopyWebpackPlugin = require("copy-webpack-plugin") //引入插件
const webpack = require('webpack')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const isProduction = process.env.NODE_ENV === 'production'
module.exports = {
    publicPath: "/",
    outputDir: "dist",
    assetsDir: "static",
    indexPath: "index.html",
    productionSourceMap: false,//去掉vuecli打包生成的map文件
    filenameHashing: true,
    devServer: {
        disableHostCheck: true,
        historyApiFallback:true,
        proxy: {
            '/api': { //请求称号
                // target: 'http://www.keledd.cn:3000', //请求的接口
                target: 'http://localhost:3000', //请求的接口
                changeOrigin: true, //允许跨域
                pathRewrite: {
                    '^/api': ''
                }
            }
        }
    },
    configureWebpack: {
        plugins: [
            new CopyWebpackPlugin({
                patterns: [{
                    from: 'node_modules/mavon-editor/dist/highlightjs',
                    to: __dirname + '/dist/highlightjs', // 插件将会把文件导出于/dist/highlightjs之下
                }, {
                    from: 'node_modules/mavon-editor/dist/markdown',
                    to: __dirname + '/dist/markdown', // 插件将会把文件导出于/dist/markdown之下
                }, {
                    from: 'node_modules/mavon-editor/dist/katex', // 插件将会把文件导出
                    to: __dirname + '/dist/katex'
                }]
            }),
            // Ignore all locale files of moment.js
            new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
            // new UglifyJsPlugin({
            //     uglifyOptions: {
            //         compress: {
            //             drop_debugger: true,
            //             drop_console: true
            //         }
            //     },
            //     sourceMap: false,
            //     parallel: true
            // }),
            // 配置compression-webpack-plugin压缩
            new CompressionWebpackPlugin({
                algorithm: 'gzip',
                test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                threshold: 10240,
                minRatio: 0.8
            })
        ]
    }
}